//
//	HOME AUTOMATION GATEWAY PROJECT
//
//	IOBusApi - Callbacks
//
//  (c) 2008 mocom software GmbH & Co KG
//	for European Microsoft Innovation Center
//
//  $Author: volker $
//  $Date: 2009-05-29 15:57:07 +0200 (Fr, 29 Mai 2009) $
//  $Revision: 368 $
//
//  Microsoft dotNetMF Project
//  Copyright ©2001,2002,2003,2004 Microsoft Corporation
//  One Microsoft Way, Redmond, Washington 98052-6399 U.S.A.
//  All rights reserved.
//  MICROSOFT CONFIDENTIAL
//
//	IOBUS is (c) 2009 mocom software GmbH & Co KG
//
//-----------------------------------------------------------------------------

#include "Microsoft_SPOT_IOBusApi.h"
#include "Microsoft_SPOT_IOBusApi_Microsoft_SPOT_IOBusApi_IOBus.h"

using namespace Microsoft::SPOT::IOBusApi;

INT64 IOBus::Enable( INT8 param0, HRESULT &hr )
{
    INT64 retVal = 0; 
	IOBusEnable(param0);
    return retVal;
}

INT64 IOBus::GetNodeState( INT32 param0, HRESULT &hr )
{
    INT64 retVal = IOBusMasterGetNodeState(param0);
    return retVal;
}

INT64 IOBus::GetNumberOfObjects( INT32 param0, HRESULT &hr )
{
    INT64 retVal = IOBusMasterGetObjects(param0);
    return retVal;
}

INT64 IOBus::GetClass( INT32 param0, INT32 param1, HRESULT &hr )
{
    INT64 retVal = IOBusMasterGetClass(param0, param1); 
    return retVal;
}

INT64 IOBus::GetType( INT32 param0, INT32 param1, HRESULT &hr )
{
    INT64 retVal = IOBusMasterGetType(param0, param1); 
    return retVal;
}

INT64 IOBus::GetPhyicalUnit( INT32 param0, INT32 param1, HRESULT &hr )
{
    INT64 retVal = IOBusMasterGetPhysicalUnit(param0, param1); 
    return retVal;
}

INT64 IOBus::ReadLong( INT32 param0, INT32 param1, HRESULT &hr )
{
    IOBusObjectValue value;
	
	if (IOBusMasterGetType(param0,param1) == OBJ_IS_ANALOG) 
	{
		hr = CLR_E_INVALID_OPERATION;
		obj = 0;
	}
	else
	{
		if (!IOBusMasterGetValue(param0,param1,&value)) {
			hr = CLR_E_INDEX_OUT_OF_RANGE;
		}
	}
    return (UINT64) value.ivalue;
}

float IOBus::ReadFloat( INT32 param0, INT32 param1, HRESULT &hr )
{
    IOBusObjectValue value;
	
	if (IOBusMasterGetType(param0,param1) != OBJ_IS_ANALOG) 
	{
		hr = CLR_E_INVALID_OPERATION;
		obj = 0;
	}
	else
	{
		if (!IOBusMasterGetValue(param0,param1,&value)) {
			hr = CLR_E_INDEX_OUT_OF_RANGE;
		}
	}
    return value.fvalue;
}

void IOBus::WriteLong( INT32 param0, INT32 param1, INT64 param2, HRESULT &hr )
{
	IOBusObjectValue value;
	
	if (IOBusMasterGetType(param0,param1) == OBJ_IS_ANALOG) 
	{
		hr = CLR_E_INVALID_OPERATION;
	} 
	else 
	{
		value.ivalue = (INT32)param2;
		if (!IOBusMasterSetValue(param0,param1,&value)) 
		hr = CLR_E_INDEX_OUT_OF_RANGE;
	}	
}

void IOBus::WriteFloat( INT32 param0, INT32 param1, float param2, HRESULT &hr )
{
	IOBusObjectValue value;
	
	if (IOBusMasterGetType(param0,param1) != OBJ_IS_ANALOG) 
	{
		hr = CLR_E_INVALID_OPERATION;
	} 
	else 
	{
		value.fvalue = param2;		
		if (!IOBusMasterSetValue(param0,param1,&value)) 
			hr = CLR_E_INDEX_OUT_OF_RANGE;
	}	
}

